﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Text;
using CoreEx.Common.Data;
using CoreEx.Database.Metadata;
using CoreEx.Database.Query;

namespace CoreEx.Database.Linq.Implementation
{
    public class TranslateResult : ITranslateResult
    {
        private IDictionary<MemberInfo, IProjectionTarget> _projectionTargets = new Dictionary<MemberInfo, IProjectionTarget>();

        public TranslateResult()
        {
            MemberResults = new Dictionary<MemberInfo, ITranslateResult>();            
        }

        public override string ToString()
        {
            if (DbExpression != null)
                return DbExpression.ToString();
            return base.ToString();
        }

        public Type ProjectedType { get; set; }
        public IExpression DbExpression { get; set; }
        public IDictionary<MemberInfo, ITranslateResult> MemberResults { get; private set; }
        public Expression Expression { get; set; }
        public Type RootType { get; set; }
        public int RootAlias { get; set; }
        public int CurrentAlias { get; set; }

        public ITableInfo TableInfo { get; set; }
        public ITranslateResult ParentTranslateResult { get; set; }
        public bool IsSubQuery { get; set; }
        public IList<Expression> LoadExpressions { get; set; }
        public ITable Table { get; set; }
        public IList Result { get; set; }


        public ITypeMappingInfo TypeMappingInfo { get; set; }
        public IDictionary<MemberInfo, IProjectionTarget> ProjectionTargets
        {
            get { return _projectionTargets; }
        }

        public IRelationLoadTarget RelationLoadTarget { get; set; }
    }
}
